# PowerShell脚本运行测试并生成报告

# 设置环境变量
$env:PLAYWRIGHT_BROWSERS_PATH = "0" # 使用系统安装的浏览器

# 获取参数
param (
    [string]$TestFile = "all", # 默认运行所有测试
    [string]$Browser = "chromium", # 默认使用Chrome浏览器 
    [switch]$Headless = $false, # 默认非无头模式
    [int]$Workers = 1 # 默认单进程运行
)

# 检查是否安装了allure命令行工具
$allureInstalled = $null
try {
    $allureInstalled = Get-Command allure -ErrorAction SilentlyContinue
} catch {
    Write-Host "Allure命令行工具未找到，将只生成结果但不会生成报告。" -ForegroundColor Yellow
    Write-Host "请访问 https://docs.qameta.io/allure/ 了解如何安装Allure命令行工具。" -ForegroundColor Yellow
}

# 构建命令
$command = "python run.py"

if ($TestFile -ne "all") {
    $command += " --tests $TestFile"
}

$command += " --browser $Browser"

if ($Headless) {
    $command += " --headless"
}

if ($Workers -gt 1) {
    $command += " --workers $Workers"
}

# 显示并执行命令
Write-Host "执行命令: $command" -ForegroundColor Cyan
Invoke-Expression $command 